import AdminUserMapping from './modules/AdminUser';
import WorkflowMapping from './modules/Workflow';

const MappingTools = {
  // 根据值获取label
  matchLabelByAllObject: function (mapping, val, labelKey = 'label') {
    for (const item in mapping) {
      if (String(mapping[item].value) === String(val)) {
        return mapping[item][labelKey];
      }
    }
    return '-';
  },
  // 根据值获取label
  matchLabel: function (mapping, val, labelKey = 'label') {
    for (const item in mapping) {
      if (String(mapping[item].value) === String(val)) {
        return mapping[item][labelKey];
      }
    }
    return '-';
  },
  // 根据值获取object
  matchObject: function (mapping, val) {
    for (const item in mapping) {
      if (String(mapping[item].value) === String(val)) {
        return mapping[item];
      }
    }
    return {};
  },
  transferOptions: (object) => {
    let options = [];
    for (const o in object) {
      if (object[o].optionHidden) continue;
      options.push(object[o]);
    }
    return options;
  },
  valueEqMapping: (mapping, val) => {
    if (typeof mapping === 'object') {
      return String(mapping.value) === String(val);
    }
    return String(mapping) === String(val);
  },
  valueInMapping(value, ...mappings) {
    for (let map of mappings) {
      let mapValue = map;
      if (typeof map === 'object') {
        mapValue = map.value;
      }
      if (String(mapValue) === String(value)) {
        return true;
      }
    }
    return false;
  },
};

export {
  MappingTools,
  // 模块
  AdminUserMapping,
  WorkflowMapping,
};
